package reduce.fz.com.reduce.abstracts;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

/**
 * Created by qingshengzheng on 15/7/23.
 */
public abstract class AbRecycleScroollListener extends RecyclerView.OnScrollListener {
    private LinearLayoutManager ll;

    public AbRecycleScroollListener(LinearLayoutManager ll) {
        this.ll = ll;

    }

    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        int lastVisibleItem = ll.findLastVisibleItemPosition();
        int totalItemCount = ll.getItemCount();
        //lastVisibleItem >= totalItemCount - 4 表示剩下4个item自动加载
        // dy>0 表示向下滑动
        if (lastVisibleItem >= totalItemCount - 1 && dy > 0) {
            onLoadMore();
        }
    }

    public abstract void onLoadMore();
}
